/*
 * Notes:
 * 1. id - NRIC? AUTO generate? Email address?
 * 2. username - shall we add this attribute for easy login, if we use AUTO generated id?
 * 3. password - I set as 12-digit random alpha-numeric password for new account.
 * 4. to-do: relationship field
 */
package entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.security.SecureRandom;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 *
 * @author Ye Mei
 */
@Entity(name="Account")
public class AccountEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String password;

    public AccountEntity() {
    }

    public void create() {
        this.setPassword();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword() {
        SecureRandom random = new SecureRandom();
        int length = 12;
        this.password = new BigInteger(130, random).toString(length);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AccountEntity)) {
            return false;
        }
        AccountEntity other = (AccountEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.AccountEntity[ id=" + id + " ]";
    }
    
}
